package com.kaoshidian.front.mongodb;

import com.kaoshidian.front.mongodb.base.BaseManage;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;

public class CritiqueManager extends BaseManage{
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		CritiqueManager cm=new CritiqueManager();
		cm.mainBody("Critique");		
	}

	public void treate(DBCollection coll) {
		delCommState(coll);
		updateSigntop(coll);
		updateCool(coll);
		mongUtil.updateObjValue(coll,"verify","NO_VERIFY","UN_VERIFY");
		mongUtil.updateObjValue(coll,"verify","NO_PASS","UN_PASS");
		mongUtil.updateObjValue(coll,"recommend","NO_RECOMMEND","UN_RECOMMEND");
	}

	public void updateVerify(DBCollection coll) {
		BasicDBObject info = new BasicDBObject();
		info.put("verify", "NO_VERIFY");
		DBCursor cur = coll.find(info);
		while (cur.hasNext()) {			
			DBObject cool=cur.next();	
			cool.put("verify", "UN_VERIFY");
			coll.save(cool);
		}	
	}
	//"verify": "NO_VERIFY",
	private void delCommState(DBCollection coll) {
		BasicDBObject info = new BasicDBObject();
		info.put("commentState", "COMMON");
		DBCursor cur = coll.find(info);
		while (cur.hasNext()) {			
			DBObject cool=cur.next();	
			if(cool.containsField("commentState")){
				cool.removeField("commentState");
			}			
			coll.save(cool);
		}	
	}
	private void updateCool(DBCollection coll) {
		BasicDBObject info = new BasicDBObject();
		info.put("cool", "COMMON");
		DBCursor cur = coll.find(info);
		while (cur.hasNext()) {			
			DBObject cool=cur.next();	
			cool.put("cool", "UN_COOL");
			coll.save(cool);
		}	
	}

	private void updateSigntop(DBCollection coll) {
		BasicDBObject info = new BasicDBObject();
		info.put("signtop", "COMMON");
		DBCursor cur = coll.find(info);
		while (cur.hasNext()) {			
			BasicDBObject cool=(BasicDBObject)cur.next();
			cool.put("signtop", "UN_SIGNTOP");
			coll.save(cool);
		}	
	}

}
